/**
 * 主要用于：PDM反写ERP接收数据状态后，更新中间表的标识符
 * 
 * @author 魏文杰 
 * @Version 1.0
 * @Date 2013-10-08
 */

package ext.generic.erp.task;

import java.io.IOException;

import ext.generic.erp.config.ERPPropertiesUtil;
import ext.generic.erp.util.IntegrationConstant;
import ext.generic.erp.util.PDMIntegrationLogUtil;

import com.infoengine.SAK.Task;
import com.infoengine.util.IEException;

public class UpdateWriteBackStatusIETask {
	private static String clazz = UpdateWriteBackStatusIETask.class.getName() ;

	private static String ieXMLFileUpdate = null ;
	
	static {
		ieXMLFileUpdate = (String) ERPPropertiesUtil.getInstance().readProperties().get(IntegrationConstant.UPDATE_WRITE_BACK_STATUS_IE_XML_FILE);
		
		initialCheck();
	}

	protected static void initialCheck() {
		if(ieXMLFileUpdate != null){
			ieXMLFileUpdate = ieXMLFileUpdate.trim() ;
			
			PDMIntegrationLogUtil.printLog(clazz, "Update Config File : " + ieXMLFileUpdate , IntegrationConstant.LOG_LEVEL_NORMAL ) ;
		}else{
			PDMIntegrationLogUtil.printLog(clazz, "Update Config File : NULL" , IntegrationConstant.LOG_LEVEL_ERROR ) ;
		}
	}	
	
	/**
	 * 在中间表中更新记录
	 * 
	 * @param part
	 * @param releaseTime
	 */
	public static void update(String table , String where){
		PDMIntegrationLogUtil.printLog(clazz, "Entering In  update(String where )......") ;
		
		PDMIntegrationLogUtil.printLog(clazz, "where = " + where ) ;
		
		if( where == null ){
			PDMIntegrationLogUtil.printLog(clazz, "update Method, where is NULL", IntegrationConstant.LOG_LEVEL_WARN);
			return ;
		}
		
		//创建任务
		Task task = new Task(ieXMLFileUpdate);
		
		task.addParam("table", table);
		task.addParam("where", where);
		task.addParam("pdmWritebackStatus", IntegrationConstant.PDM_WRITE_BACK ) ;
		
		try {
			task.invoke();
		} catch (IEException e) {
			PDMIntegrationLogUtil.printLog(clazz, "Throws IEException", IntegrationConstant.LOG_LEVEL_ERROR);
			PDMIntegrationLogUtil.printLog(clazz, e.toString() , IntegrationConstant.LOG_LEVEL_ERROR);
			
			e.printStackTrace();
		} catch (IOException e) {
			PDMIntegrationLogUtil.printLog(clazz, "Throws IOException", IntegrationConstant.LOG_LEVEL_ERROR);
			PDMIntegrationLogUtil.printLog(clazz, e.getMessage(), IntegrationConstant.LOG_LEVEL_ERROR);
			
			e.printStackTrace();
		}finally{
			PDMIntegrationLogUtil.printLog(clazz, "Existed Out  update(String where )......") ;
		}
	}
}
